<?php
/**
 * PHP versions 4 and 5
 * MagicPHP
 * Licensed under The Open Group Test Suite License
 * Redistributions of files must retain the above copyright notice.
 * @copyright     Copyright 2011
 * @link
 * @package       Model
 * @since         MaginPHP 1.0
 * @license
 */
?>
<?php
/**
 * This class is used to import muliple class and function at instace time
 */
class Magic_ClassUpload_Model  {
            /**
             * @desc : array of function 
             */
            public $functionarr=array();
            /**
             * @desc : Variable of class
             */
            public  $class ;
            /**
             * @desc: This function is used to import class
             * @version 1.0
             * @param $class: array of class that you want to include 
             * @return array
             */
            public function uploadClass($class) {
                $this->class=$class;
                if(is_array($class) === true) {
                    for($i=0;$i<count($class) ; $i++) {
                        $this->$class[$i]=new $class[$i];
                        $this->functionarr[$class[$i]]=(get_class_methods($this->$class[$i]));;
                    }
                }
                return $this->functionarr;
            }
            /**
             * @desc: Magic PHP Meathod
             */
            public function __call($method, $args){
                    $arr_key=array();
                    $classname='';
                    foreach ($this->functionarr as $key => $value){
                        $arr_key[]=$key;
                    }
                    for($i=0;$i<count($arr_key); $i++) {
                        if(in_array($method, $this->functionarr[$arr_key[$i]])) {
                            $classname=$arr_key[$i];
                            break;
                        }
                    }
                    if($classname != ''){
                       return call_user_func_array(array($classname, $method), $args);
                    } else {
                       return 'Call to undefined method/class function: ' . $method;
                    }
               }

        }
?>